package com.xiaomi.shwx.controller;

import com.xiaomi.shwx.common.result.Result;
import com.xiaomi.shwx.service.StorageService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @program: after-sales-maintenance
 * @description: 存储图片/视频控制层
 * @author: Yangziyin
 * @create: 2024-05-16 23:36
 **/

@RestController
@RequestMapping("/api/upload")
public class StorageController {
    @Resource
    private StorageService storageService;

    @PostMapping("/image")
    public Result<String> uploadImage(@RequestPart("file") MultipartFile file, @RequestParam("bizDesc") String bizDesc, @RequestParam("id") String id) {
        return storageService.uploadImage(bizDesc, id, file) ? Result.ok() : Result.fail();
    }

    @PostMapping("/video")
    public Result<String> uploadVideo(@RequestPart("file") MultipartFile file, @RequestParam("bizDesc") String bizDesc, @RequestParam("id") String id) {
        return storageService.uploadVideo(bizDesc, id, file) ? Result.ok() : Result.fail();
    }
}
